package com.mydemo.likedy.authority;

import com.mydemo.likedy.Utils.JwtUtils;
import com.mydemo.likedy.holder.UserHolder;
import com.mydemo.likedy.properties.UserJwtProperties;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

public class BaseAuthority implements AuthorityVerify {
    @Override
    public Boolean authorityVerify(HttpServletRequest request, String[] permissions) {
        if (!JwtUtils.checkToken(request.getHeader("token"),"likedywithtest-likedywithtest-tests")) {
            return false;
        }
        // 获取当前用户权限
        Long uId = UserHolder.get();
        for (String permission : permissions) {
            if (!AuthorityUtils.verify(uId,permission)) {
                return false;
            }
        }

        return true;
    }
}
